win32: Export _gtk_win32_theme_part_create_surface()
authorBenjamin Otte <otte@redhat.com>
Tue, 20 Dec 2011 13:40:07 +0000 (14:40 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Jan 2012 17:37:56 +0000 (18:37 +0100)
gtk/gtkwin32theme.c
gtk/gtkwin32themeprivate.h

index 5e4041f1ff97a7348407c40b6a2a919f1fc01a29..398ff3ed3ba08c62e825380d07b4d9e85f1fb541 100644 (file)
@@ -426,15 +426,18 @@ _gtk_win32_theme_part_parse (GtkCssParser *parser,
   return 1;
 }
 
-#ifdef G_OS_WIN32
 cairo_surface_t *
-_gtk_win32_theme_part_create_surface  (GtkWin32ThemePart  *part,
-                                      int                 xp_part,
-                                      int                 state,
-                                      int                 width,
-                                      int                 height)
+_gtk_win32_theme_part_create_surface (HTHEME theme,
+                                      int    xp_part,
+                                     int    state,
+                                     int    margins[4],
+                                     int    width,
+                                      int    height)
 {
   cairo_surface_t *surface;
+  GdkRGBA color;
+  cairo_t *cr;
+#ifdef G_OS_WIN32
   HDC hdc;
   RECT rect;
   HRESULT res;
@@ -442,37 +445,48 @@ _gtk_win32_theme_part_create_surface  (GtkWin32ThemePart  *part,
   surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32, width, height);
   hdc = cairo_win32_surface_get_dc (surface);
   
-  rect.left = part->margins[3];
-  rect.top = part->margins[0];
-  rect.right = width - part->margins[1];
-  rect.bottom = height - part->margins[2];
+  rect.left = margins[3];
+  rect.top = margins[0];
+  rect.right = width - margins[1];
+  rect.bottom = height - margins[2];
+
+  res = draw_theme_background (theme, hdc, xp_part, state, &rect, &rect);
+  if (res == S_OK)
+    return surface;
+#else /* !G_OS_WIN32 */
+  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+#endif /* G_OS_WIN32 */
 
-  res = draw_theme_background (part->theme, hdc, xp_part, state, &rect, &rect);
+  cr = cairo_create (surface);
+  
+  /* XXX: Do something better here (like printing the theme parts) */
+  gdk_rgba_parse (&color, "pink");
+  gdk_cairo_set_source_rgba (cr, &color);
+  cairo_paint (cr);
+
+  cairo_destroy (cr);
+  
   return surface;
 }
-#endif
-
 
 cairo_pattern_t *
 _gtk_win32_theme_part_render  (GtkWin32ThemePart  *part,
                               int                 width,
                               int                 height)
 {
-#ifdef G_OS_WIN32
   cairo_surface_t *surface, *surface2, *image;
   cairo_pattern_t *pattern;
   cairo_t *cr;
   cairo_matrix_t matrix;
   cairo_user_data_key_t key;
 
-  surface = _gtk_win32_theme_part_create_surface  (part, part->part, part->state, 
-                                                  width, height);
+  surface = _gtk_win32_theme_part_create_surface (part->theme, part->part, part->state, part->margins,
+                                                 width, height);
   
   if (part->state2 >= 0)
     {
-      surface2 = _gtk_win32_theme_part_create_surface  (part, part->part2, part->state2, 
-                                                       width, height);
-
+      surface2 = _gtk_win32_theme_part_create_surface (part->theme, part->part2, part->state2, part->margins,
+                                                      width, height);
 
       cr = cairo_create (surface);
 
@@ -487,9 +501,13 @@ _gtk_win32_theme_part_render  (GtkWin32ThemePart  *part,
       cairo_surface_destroy (surface2);
     }
 
+#ifdef G_OS_WIN32
   /* We need to return an image surface, as that is what the code expects in order
      to get the size */
   image = cairo_win32_surface_get_image (surface);
+#else
+  image = surface;
+#endif
   pattern = cairo_pattern_create_for_surface (cairo_surface_reference (image));
 
   cairo_matrix_init_scale (&matrix,
@@ -504,13 +522,6 @@ _gtk_win32_theme_part_render  (GtkWin32ThemePart  *part,
                               surface, (cairo_destroy_func_t) cairo_surface_destroy);
 
   return pattern;
-#else
-  GdkRGBA color;
-  
-  gdk_rgba_parse (&color, "pink");
-
-  return cairo_pattern_create_rgb (color.red, color.green, color.blue);
-#endif
 }
 
 int
index 575f829414ef8c2c6a09362be08595d127464754..c34798792a90696f670e55f77e46a5db70cdd9d0 100644 (file)
@@ -45,6 +45,12 @@ typedef struct _GtkWin32ThemePart GtkWin32ThemePart;
 #define GTK_TYPE_WIN32_THEME_PART (_gtk_win32_theme_part_get_type ())
 
 HTHEME             _gtk_win32_lookup_htheme_by_classname (const char  *classname);
+cairo_surface_t *  _gtk_win32_theme_part_create_surface  (HTHEME       theme,
+                                                          int          xp_part,
+                                                          int          state,
+                                                          int          margins[4],
+                                                          int          width,
+                                                          int          height);
 
 GType              _gtk_win32_theme_part_get_type  (void) G_GNUC_CONST;